/**
 * Created by xiao++ on 7/13/16.
 */
import alt from '../alt';
import UploadFileActions from '../actions/UploadFileActions';

/**
 * 这里的store做了几件事:
 * 1. 和Footer的action绑定在一起,绑定就等价于订阅了actions.
 * 2. 初始化了一个characters空数组,这个空数组会和React的state绑定  参考文档:http://alt.js.org/docs/createStore/#storemodelbindlisteners
 */
class UploadFileStore {
    constructor() {
        this.bindActions(UploadFileActions);
        this.pic = '';
        this.file = '';
        this.age = '';
        this.sex = '';
    }

    addFormSuccess(data) {
        this.characters = data.slice(0, 5);
    }

    addFormFail(jqXhr) {
        toastr.error(jqXhr.responseJSON && jqXhr.responseJSON.message || jqXhr.responseText || jqXhr.statusText);
    }

    onUpdatePic(event) {
        this.pic = event.target.value;
    }

    onUpdateFile(event) {
        console.info('file',event.target);
        this.file = event.target.value;
    }

    onUpdateSex(event) {
        this.sex = event.target.value;
    }

    onUpdateAge(event){
        this.age = event.target.value;
    }
}

export default alt.createStore(UploadFileStore);